function [ps_start]=parse_cond_starts(ps_raw,min_dur,refract_time,start_or_end)

ps_start_ind=[];
ps_end_ind=[];

ps_raw(end)=0;

% if ps_raw(1)==1
%     for ind=1:length(ps_raw)
%         if ps_raw(ind)==0
%             ps_raw(1:ind)=0;
%             break
%         end
%     end
% end
% 
% 
% 
% ps_start_ind=find(diff(ps_raw)==1);
% ps_end_ind=find(diff(ps_raw)==-1);
% 
% cnt=0;
% while cnt<length(ps_start_ind)-1
%     cnt=cnt+1;
%     if ps_start_ind(cnt+1)-ps_end_ind(cnt)<refract_time
%         ps_start_ind=ps_start_ind([1:cnt cnt+2:end]);
%         ps_end_ind=ps_end_ind([1:cnt-1 cnt+1:end]);
%         cnt=cnt-1;
%     end
% end
% 
% 
% ps_ind_mindur=(ps_end_ind-ps_start_ind)>min_dur;
% ps_start_ind=ps_start_ind(ps_ind_mindur);
% ps_end_ind=ps_end_ind(ps_ind_mindur);
% 
% ps_ind_refract=logical([1 ((ps_start_ind(2:end)-ps_end_ind(1:end-1))>refract_time)']);
% if start_or_end==1;
%     ps_start=ps_start_ind(ps_ind_refract)*10;
% elseif start_or_end==2;
%     ps_start=ps_end_ind(ps_ind_refract)*10;
% end



start_search=0;
end_search=0;
cnt=0;
refract_count=0;
for ind=1:length(ps_raw)
    refract_count=refract_count+1;
    
    if ps_raw(ind)==0 & start_search==0
        start_search=1;
    end
    
    if ps_raw(ind)==1 & start_search==1 & refract_count>refract_time
        cnt=cnt+1;
        ps_start_ind(cnt)=ind;
        start_search=0;
        end_search=1;
    end
    
    if ps_raw(ind)==0 & end_search==1;
        ps_end_ind(cnt)=ind;
        end_search=0;
        if (ps_end_ind(cnt)-ps_start_ind(cnt))>min_dur
            refract_count=0;
        end
    end
end
ps_ind=(ps_end_ind-ps_start_ind)>min_dur;
ps_start=ps_start_ind(ps_ind)*10;
